<?php
class User {
	private $id;
	private $name;
	private $email;
	private $image;
	private $username;
	private $password;
	private $type;
	private $createDate;
	private $lastVisit;
	
	function __construct($id,$name, $email, $image, $username, $password, $type, $createdate, $lastVisit){
		$this -> id = $id;
		$this -> name = $name;
		$this -> email = $email;
		$this -> image = $image;
		$this -> username = $username;
		$this -> password = $password;
		$this -> type = $type;
		$this -> createdate = $createdate;
		$this -> lastVisit = $lastVisit;
	}
	
	function login($db, $username, $password){
		$username = utf8_decode(addslashes($username));
		$password = md5($password);
		
		$result = $db->query("SELECT use_IDuser FROM user WHERE use_password = '$password' AND use_username = '$username'" ,4);
		$id = $result;
	
		if(is_numeric($id)){
			$user=User::getUser($db,$id);
			return $user;
		}
		
		return "error";
	}
	
	

	function getUser($db,$id){
		$result=$db->query("SELECT * FROM user WHERE use_IDuser = $id",2);
		$user=new User(	$result[0]['use_IDuser'],
						$result[0]['use_name'], 
						$result[0]['use_email'],
						$result[0]['use_image'],
						$result[0]['use_username'],
						$result[0]['use_password'],
						$result[0]['use_id_userType'],
						$result[0]['use_regDate'],
						$result[0]['use_lastVisit']);
				
		return $user;
	
	}
	
	function insert($db,$user){
		$name 		= $user -> getName();
		$email		= $user -> getEmail();
		$image 		= $user -> getImage();
		$username 	= $user -> getUsername();
		$password 	= $user -> getPassword();
		$type 		= $user -> getType();
		$result=$db->insert("INSERT INTO user (use_name,use_email,use_image,use_username,use_password,use_id_usertype,use_regDate,use_lastVisit)
										 VALUES('".addslashes(utf8_decode($name))."','$email','$image','$username',md5('$password'),
										 $type,now(),now())");
		return $result;
	}		
	
	function getId(){
		return $this -> id;
	}
	
	function setId($id){
		$this -> id = $id;
	}
	
	
	function getName(){
		return $this -> name;
	}	
	
	function  setName($name){
		$this -> name = $name;
	}	
	
	function getEmail(){
		return $this -> email;
	}	
	
	function  setEmail($email){
		$this -> email = $email;
	}	
	
	function getImage(){
		return $this -> image;
	}
	
	function  setImage($image){
		$this -> image = $image;
	}	
	
	function getUsername(){
		return $this -> username;
	}
	
	function  setUsername($username){
		$this -> username = $username;
	}
	
	function getPassword(){
		return $this -> password;
	}
	
	function  setPassword($password){
		$this -> password = $password;
	}

	
	function getType(){
		return $this -> type;
	}
	
	function  SetType($type){
		$this -> type = $type;
	}
	
	function getCreateDate(){
		return $createdate -> createdate;
	}
	
	function  SetCreateDate($createdate){
		$this -> createdate = $createdate;
	}
	
	function getLastVisit(){
		return $lastVisit -> lastVisit;
	}
	
	function  SetLastVisit($lastVisit){
		$this -> lastVisit = $lastVisit;
	}
}

?>